package br.com.viewcar.web.bean;

import br.com.viewcar.util.CheckrotaUtil;

public abstract class BaseStateBean extends BaseBean {

	private String currentState;

	public boolean isOpened() {

		Object tmp = CheckrotaUtil.getSession().getAttribute("isOpen");

		if (tmp == null) {

			closePopup();

			return false;

		} else {

			return (Boolean) tmp;
		}
	}

	public String openPopup() {

		CheckrotaUtil.getSession().setAttribute("isOpen", Boolean.TRUE);

		return SUCCESS;
	}

	public String closePopup() {

		CheckrotaUtil.getSession().setAttribute("isOpen", Boolean.FALSE);

		return SUCCESS;
	}

	protected String currentBeanName() {

		return this.getClass().getSimpleName();
	}

	protected void setCurrentBean(String bean) {

		CheckrotaUtil.getSession().setAttribute("currentBean", bean);
	}

	protected void setCurrentState(String state) {

		this.currentState = state;
	}

	public String getCurrentBean() {

		return (String) CheckrotaUtil.getSession().getAttribute("currentBean");
	}

	public String getCurrentState() {

		return this.currentState == null ? "" : this.currentState;
	}
}